package com.coship.vasms.adstorm.common.log;


import java.io.File;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

public class LoggerFactory {
  /**
   * 获得写日志对�?
   *
   * @param className
   *            类明
   * @return
   */
  public static JLogger getBizLogger(String className) {
    // BizLogger bizLog = null;
    Logger log = Logger.getLogger(className);
    JLoggerImpl bizLog = new JLoggerImpl(log);
    return bizLog;
  }

  /**
   * 获得写日志对�?
   *
   * @param className
   * @return
   */
  public static JLogger getLogger(Class className) {
    Logger log = org.apache.log4j.Logger.getLogger(className);
    JLoggerImpl logerimp = new JLoggerImpl(log);
    return logerimp;
  }



  /**
   * 初始化Log4j方法
   *
   * @param file
   * @param refresh
   */
  public static synchronized void configLog(String file, int refresh) {
    if(isConfigOk)
      return;
    if ( (file == null) || file.equals("")) {
      System.err.println("log4j.xml not set");
      return;
    }
    System.err.println("Config file:" + file);
    File confFile = new File(file);
    if (!confFile.exists()) {
      System.err.println("log4j.xml not found");
      return;
    }
    System.out.println("refresh time:" + refresh);
    DOMConfigurator.configureAndWatch(file, refresh * 1000);
    isConfigOk = true;
    System.out.println("Config log successfully");
  }
  private static boolean isConfigOk = false;
}
